home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UUPC11QS.ARJ / FOPEN.C < prev    next >
C/C++ Source or Header  |  1991-11-21  |  2KB  |  58 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    f o p e n . c                                                   */
  3. /*                                                                    */
  4. /*    Support routines for UUPC/extended                              */
  5. /*                                                                    */
  6. /*    Changes Copyright 1990, 1991 (c) Andrew H. Derbyshire           */
  7. /*                                                                    */
  8. /*    History:                                                        */
  9. /*       21Nov1991 Break out of lib.c                          ahd    */
  10. /*--------------------------------------------------------------------*/
  11.  
  12. #include <fcntl.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <time.h>
  17.  
  18. /*--------------------------------------------------------------------*/
  19. /*                    UUPC/extended include files                     */
  20. /*--------------------------------------------------------------------*/
  21.  
  22. #include "lib.h"
  23. #include "hlib.h"
  24.  
  25. /*--------------------------------------------------------------------*/
  26. /*    F O P E N                                                       */
  27. /*                                                                    */
  28. /*    Like fopen() but create imtermediate directories                */
  29. /*                                                                    */
  30. /*    This routine has dependency on the path separator characters    */
  31. /*    being '/', we should relove that somehow someday.               */
  32. /*--------------------------------------------------------------------*/
  33.  
  34. FILE *FOPEN(const char *name, const char *mode, const char ftype)
  35. {
  36.  
  37.    char *last;
  38.    FILE *results;
  39.  
  40.    /* are we opening for write or append */
  41.    FILEMODE(ftype);
  42.    results = fopen(name, mode);
  43.  
  44.    if ((results != nil(FILE)) || (*mode == 'r'))
  45.       return results;
  46.  
  47.    /* verify all intermediate directories in the path exist */
  48.    if ((last = strrchr(name, '/')) != nil(char)) {
  49.       *last = '\0';
  50.       MKDIR(name);
  51.       *last = '/';
  52.    }
  53.  
  54.    /* now try open again */
  55.    return fopen(name, mode);
  56.  
  57. } /*FOPEN*/
  58.